package main

import (
	"encoding/json"
	"fmt"
	"net"
	"strconv"
	"strings"
)

type IControl interface {
}

type Control struct {
	client net.Conn //Client 客户端连接
}

//初始化
func (control Control) Control(conn net.Conn) {
	control.client = conn
	control.run()
}

//run
func (con Control) run() {
	for true {
		if con.processRequest() == false {
			return
		}
	}
}

//处理请求
func (control Control) processRequest() bool {
	var recvBuff [1024]byte
	var data string

	fmt.Print("处理客户请求\n")
	n, err := control.client.Read(recvBuff[0:1024])
	if err != nil {
		fmt.Print("读取数据出错")
		return false
	}

	fmt.Print("长度: " + strconv.Itoa(n) + "\n")

	data = string(recvBuff[0:1024])

	sArry := strings.Split(data, "\x00")

	data = sArry[0]

	fmt.Println(recvBuff)
	fmt.Println("json: " + data)

	var mjson map[string]string
	err = json.Unmarshal([]byte(data), &mjson)
	if err != nil {
		fmt.Println("JsonToMapDemo err: ", err)
	}
	fmt.Println(mjson)
	hexstring := mjson["info"]
	buffer := HexstringToByte(hexstring)
	var info ForwardInfo
    
	src := *[272]byte)

	return true
}
